package com.bazaaroid.server.gae.api.resources;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

import com.bazaaroid.server.gae.business.facade.SearchFacade;
import com.bazaaroid.server.gae.core.dto.partner.ProductSearchResultsDTO;
import com.bazaaroid.server.gae.core.ioc.GuiceFactory;

@Path("/search/")
public class SearchResource {

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/products/{searchQuery}")
	public ProductSearchResultsDTO searchProducts(
			@PathParam("searchQuery") String searchQuery) {
		SearchFacade searchFacade = GuiceFactory.getInjector()
			.getInstance(SearchFacade.class);
		return searchFacade.searchProducts(searchQuery);
	}

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/products")
	public ProductSearchResultsDTO searchProducts(@Context UriInfo ui) {
		SearchFacade searchFacade = GuiceFactory.getInjector()
			.getInstance(SearchFacade.class);
		return searchFacade.searchProducts(ui.getQueryParameters());
	}

}
